<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
function doubleClick(x, y) {
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    eventSender.mouseDown();
    eventSender.mouseUp();
}

test(() => {
    const isWin = navigator.platform.indexOf('Win') == 0;

    assert_not_equals(window.eventSender, undefined,
        'This test requires window.eventSender');

    assert_selection(
        '<div contenteditable><span id="dragme">hello</span> world</div>',
        selection => {
            const dragMe = selection.document.getElementById('dragme');
            const x = dragMe.offsetLeft + selection.document.offsetLeft + 3;
            const y = dragMe.offsetTop + selection.document.offsetTop + 3;

            // Select "hello"
            doubleClick(x, y);

            // Drag 'hello'
            eventSender.mouseMoveTo(x + dragMe.offsetWidth / 2, y);
            eventSender.mouseDown();
            // and drop it off to the right somewhere.
            eventSender.leapForward(500);
            eventSender.mouseMoveTo(x + dragMe.offsetWidth + 100, y);
            eventSender.mouseUp();
        },
        [
            '<div contenteditable>',
                isWin
                    ? 'world<span id="dragme">^\u{00A0}hello</span>\u{00A0}|'
                    : 'world^\u{00A0}hello|',
            '</div>',
        ].join(''),
        'drag-and-drop after double-click does a smart drag');
});
</script>
